package com.yyjj.yyjj.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yyjj.yyjj.common.result.Result;
import com.yyjj.yyjj.model.sys.RegionWare;
import com.yyjj.yyjj.sys.service.IRegionWareService;
import com.yyjj.yyjj.vo.sys.RegionWareQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Api(tags = "开通区域接口")
@RequiredArgsConstructor
@RequestMapping(value = "/admin/sys/regionWare")
public class RegionWareController {
    private final IRegionWareService regionWareService;


    //开通区域列表
    @ApiOperation(value = "获取开通区域列表")
    @GetMapping("/{page}/{limit}")
    public Result list(@PathVariable("page") Long page, @PathVariable("limit") Long limit, RegionWareQueryVo regionWareQueryVo) {
        Page<RegionWare> warePage = new Page<>(page, limit);
        IPage<RegionWare> pageRegionWare = regionWareService.selectPageRegionWare(warePage, regionWareQueryVo);
        return Result.ok(pageRegionWare);
    }

    //添加开通区域
    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public Result addRegionWare(@RequestBody RegionWare regionWare){
        regionWareService.saveRegionWare(regionWare);
        return Result.ok(null);
    }

    //删除开通区域
    @ApiOperation(value = "删除")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long id) {
        regionWareService.removeById(id);
        return Result.ok(null);
    }

    @ApiOperation(value = "取消开通区域")
    @PostMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id,@PathVariable Integer status) {
        regionWareService.updateStatus(id, status);
        return Result.ok(null);
    }

}
